
package com.springboot.core.log.event;

import com.alibaba.fastjson.JSON;
import com.springboot.system.domain.log.SysLog;
import com.springboot.system.service.LogService;

import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
 * 
 * @author xyy
 *
 */
public class SysLogListener {

	private LogService remoteLog;

	public SysLogListener(LogService remoteLog) {
		this.remoteLog = remoteLog;
	}

	/**
	 * 异步写入日志
	 * 
	 * @param event
	 */
	@Async
	@EventListener(SysLogEvent.class)
	public void saveSysLog(SysLogEvent event) {
		SysLog bLog = (SysLog) event.getSource();
		if (remoteLog == null) {
			System.out.println(JSON.toJSONString(bLog));
		} else {
			remoteLog.insert(bLog);
		}

	}

}
